package de.elmar_baumann.nb.slclock;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

public final class StausLineClockOptionsPanel extends javax.swing.JPanel {

    private static final long serialVersionUID = 1L;

    private final StausLineClockOptionsPanelController controller;

    StausLineClockOptionsPanel(StausLineClockOptionsPanelController controller) {
        this.controller = controller;
        initComponents();
        panelAlarmEvents.listenToModelChanges(true);
        panelTimerEvents.listenToModelChanges(true);
        panelClockPreferences.addPropertyChangeListener("changed", clockChangeListener);
        // TODO listen to changes in form fields and call controller.changed()
    }

    void load() {
        // TODO read settings and initialize GUI
        // Example:
        // someCheckBox.setSelected(Preferences.userNodeForPackage(ClockOptionsPanel.class).getBoolean("someFlag", false));
        // or for org.openide.util with API spec. version >= 7.4:
        // someCheckBox.setSelected(NbPreferences.forModule(ClockOptionsPanel.class).getBoolean("someFlag", false));
        // or:
        // someTextField.setText(SomeSystemOption.getDefault().getSomeStringProperty());
    }

    void store() {
        if (panelClockPreferences.isChanged()) {
            panelClockPreferences.persistFormat();
        }
    }

    boolean valid() {
        return true;
    }

    private final PropertyChangeListener clockChangeListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if ("changed".equals(evt.getPropertyName())) {
                controller.changed();
            }
        }
    };

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
     * content of this method is always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        tabbedPane = new javax.swing.JTabbedPane();
        panelClockPreferences = new de.elmar_baumann.nb.slclock.clock.ClockPreferencesPanel();
        panelAlarmEvents = new de.elmar_baumann.nb.slclock.alarmclock.AlarmEventsPanel();
        panelTimerEvents = new de.elmar_baumann.nb.slclock.timer.TimerEventsPanel();

        setLayout(new java.awt.GridBagLayout());

        tabbedPane.addTab(org.openide.util.NbBundle.getMessage(StausLineClockOptionsPanel.class, "StausLineClockOptionsPanel.panelClockPreferences.TabConstraints.tabTitle"), panelClockPreferences); // NOI18N
        tabbedPane.addTab(org.openide.util.NbBundle.getMessage(StausLineClockOptionsPanel.class, "StausLineClockOptionsPanel.panelAlarmEvents.TabConstraints.tabTitle"), panelAlarmEvents); // NOI18N
        tabbedPane.addTab(org.openide.util.NbBundle.getMessage(StausLineClockOptionsPanel.class, "StausLineClockOptionsPanel.panelTimerEvents.TabConstraints.tabTitle"), panelTimerEvents); // NOI18N

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        add(tabbedPane, gridBagConstraints);
    }//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private de.elmar_baumann.nb.slclock.alarmclock.AlarmEventsPanel panelAlarmEvents;
    private de.elmar_baumann.nb.slclock.clock.ClockPreferencesPanel panelClockPreferences;
    private de.elmar_baumann.nb.slclock.timer.TimerEventsPanel panelTimerEvents;
    private javax.swing.JTabbedPane tabbedPane;
    // End of variables declaration//GEN-END:variables
}
